package core.category.helper;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.StringTokenizer;

import core.category.model.Category;

import backend.category.manager.CategoryManager;

public class CategoryPath 
{
	private String path ;
	private Map<Long,String> pathMap ;
	private CategoryManager cm ;
	
	public CategoryPath(String path)
	{
		 this.path = path ;
		 cm = new CategoryManager();
		 pathMap = new LinkedHashMap<Long,String>();
	}
	
	public Map<Long,String> getPathMap()
	{
		StringTokenizer pathSep = new StringTokenizer(path,"/");
		while(pathSep.hasMoreTokens())
		{
			Long uuid = Long.parseLong(pathSep.nextToken());
			Category cate = cm.getCategoryByUuid(uuid);
			
			pathMap.put(uuid, cate.getName());
		}
		return this.pathMap;
	}
	
	// this code is used for testing of getPathMap() method
	// otherwise is code would be called by controller
	public static void main(String argv[])
	{
		CategoryPath cp = new CategoryPath("/1/2/3/4");
		cp.getPathMap();
	}
}
